package org.linlinjava.litemall.admin.web;

import io.swagger.annotations.ApiOperation;
import org.linlinjava.litemall.core.util.R;
import org.linlinjava.litemall.db.domain.SystemParam;
import org.linlinjava.litemall.db.service.SystemParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system_param")
public class SystemParamController {

    @Autowired
    private SystemParamService systemParamService;


    @GetMapping("/list")
    public Object list(@RequestParam(required = false) String code,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit) {
        return R.okList(systemParamService.list(code, page, limit));
    }


    @ApiOperation(value = "系统参数新增和更新", notes = "接收code、value、detail字段，带id为更新，不带id为新增")
    @PostMapping("/save")
    public Object save(@RequestBody SystemParam systemParam) {
        String res = systemParamService.save(systemParam);
        if (res == null)
            return R.ok(systemParam);
        else
            return R.fail(res);
    }
}
